{extend name="public:base" /}
{block name="head"}
<link href="__PUBLIC__/view_res/mobile/css/wshop_company_center.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/jquery-weui/dist/lib/weui.min.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/view_res/mobile/css/login.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/jquery-weui/dist/lib/weui.min.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/jquery-weui/dist/css/jquery-weui.min.css" type="text/css" rel="Stylesheet" />
<script src="__PUBLIC__/jquery-weui/dist/js/jquery-weui.min.js"></script>

{/block} 
{block name="header"}
{include file="public/top-nav" /}
{/block}

{block name="content"}

    <header class="Thead">交易品兑换</header>

    {:token()}

    <div style="margin:0 10px;">
        <div class="gs-text">
            <input type="number" name="num" value=""  tabindex="2" placeholder="请输入兑换枚数" />
        </div>
    </div>
    <div style="margin:0 10px;">
        <div class="gs-text">
            <input type="password" name="pwd2" value=""  tabindex="2" placeholder="请输入二级密码" />
        </div>
    </div>
    <input class="button green" id="reg-btn" type="submit" value="确认提交">
    <script type="text/javascript">
        $('#exchange_id').change(function(){
            //alert("abc");
            var iframe_array = <?php echo  json_encode($variety);   ?>;
            var checkValue=jQuery("#exchange_id").val();
            //alert(checkValue);
            $("#variety_id").empty();
            for (var i = 0; i <iframe_array.length ; i++)
            {
                if(iframe_array[i]['exchange_id']==checkValue)
                {
                    var opt = "<option value='"+iframe_array[i]['id']+"'>"+iframe_array[i]['name']+"</option>";
                    jQuery("#variety_id").append(opt);
                }
            }

        })
    </script>
    <script>
        $('#reg-btn').click(function(){

            var password    = $('input[type="password"]').val();
            var number      = $('input[type="number"]').val();
            var hidden      = $('input[type="hidden"]').val();

            $.ajax({
                url : '{:url("MyTicket/wd")}',
                data : {exchange_id:exchange_id,variety_id:variety_id,pwd2:password,num:number,token:hidden},
                type : 'post',
                success:function(d){
                    if(d.error){
                        $.toast(d.error, "forbidden");
                    }else if(d.success){
                        $.toast(d.success);
                        setTimeout(function (){
                            window.location.href = "/mobile/MyTicket/index";
                        },1000);
                    }
                }
            });

        });
    </script>
{/block}